package com.live.dengdengtv.net;

import android.app.Activity;
import android.util.Log;

import com.google.gson.Gson;
import com.live.dengdengtv.activity.support.CurLiveInfo;
import com.live.dengdengtv.bean.AppInfo;
import com.live.dengdengtv.bean.LoginInfo;
import com.live.dengdengtv.bean.SimpleInfoData;
import com.live.dengdengtv.bean.gson.GUserInfo;
import com.live.dengdengtv.net.callback.ProgressDialogCallBack;
import com.live.dengdengtv.net.callback.RequestNetCallback;
import com.live.dengdengtv.utils.Lo;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.Callback;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Response;


/**
 * Created by wyf on 2016/8/2.
 */
public class NetTaskList {

    private static NetTaskList request = new NetTaskList();
    private NetTaskList(){ }
    public static NetTaskList getInstance() {
        return request;
    }

    public static final String BASEURL  = "http://182.92.104.220/DdLive/appapi/";
    public static final String login  = BASEURL + "member/phone_login";
    public static final String login_code  = BASEURL + "member/code_login";
    public static final String modify_password  = BASEURL + "member/modify_password";
    public static final String register  = BASEURL + "member/register";
    public static final String getVerify  = BASEURL + "sendmessage/get_message";
    public static final String login_open = BASEURL + "member/open_platform_login";
    /**完善个人信息*/
    public static final String update_personalInfo  = BASEURL + "member/supplement_info";
    public static final String get_userInfo  = BASEURL + "member/get_user_info";
    public static final String get_bannerList  = BASEURL + "ads/banner_list";

    public static final String room_id  = BASEURL + "live/get_room_id";//获取room_id
    public static final String create_live  = BASEURL + "live/create_live";//创建直播
    public static final String end_live  = BASEURL + "live/end_live";//结束直播
    public static final String live_list  = BASEURL + "live/live_list";//直播列表
    public static final String follow_List  = BASEURL + "friend/concern_list";//关注列表
    public static final String friend_list  = BASEURL + "friend/friend_list";//好友列表
    public static final String fans_list  = BASEURL + "friend/fans_list";//好友列表
    public static final String follow_member  = BASEURL + "friend/follow_member";//关注

    public static final String add_blacklist  = BASEURL + "blacklist/add_blacklist";//拉黑
    public static final String del_blacklist  = BASEURL + "blacklist/del_blacklist";//移除黑名单
    public static final String get_blacklist  = BASEURL + "blacklist/get_blacklist";//获取黑名单列表

    /* 话题 */
    public static final String add_topic  = BASEURL + "topic/add_topic";//添加话题
    public static final String topic_list  = BASEURL + "topic/topic_list";//话题列表

    public static final String search_recommend  = BASEURL + "live/search_recommend";//热搜话题推荐


    public static final String virtual_coin  = BASEURL + "redPacket/get_user_virtual_coin";//
    public static final String user_level  = BASEURL + "experience/get_user_level";//获取用户等级
    public static final String get_contribution_list  = BASEURL + "prop/get_contribution_list";//贡献榜

    public static final String wechatpay  = BASEURL + "  recharge/get_info_for_wechatpay";//微信支付

    public static final String send_gift  = BASEURL + "prop/send_prop";//赠送礼物
    public static final String send_redpacket  = BASEURL + "redPacket/send_redpacket";//发红包
    public static final String get_redpacket  = BASEURL + "redPacket/get_redpacket";//抢红包

    public static final String exchange  = BASEURL + "earn/exchange";//虚拟礼券兑换虚拟币、现金
    public static final String exchange_record  = BASEURL + "earn/get_exchange_list";//获取兑换记录


    public static final String add_comment  = BASEURL + "video/add_comment";//添加评论
    public static final String get_comments  = BASEURL + "video/get_comments";//获取评论

    public static final String add_record  = BASEURL + "MakeVideo/add";//添加录播视频
    public static final String get_recordList  = BASEURL + "MakeVideo/get_videos_by_userid";//我的录播


    public static void addRecord(Map<String, String> params){
        OkHttpUtils
                .post()
                .url(NetTaskList.add_record)
                .params(params)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        e.printStackTrace();
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.e("addRecord", response);
                    }
                });

    }
    public void lognTask(String jsonString, Callback callback){
        OkHttpUtils
                .postString()
                .url(NetTaskList.login)
                .content(jsonString)
                .build()

                .execute(callback);

    }

    public void loginOpenTask(String jsonString, Callback callback) {
        OkHttpUtils.postString()
                .url(NetTaskList.login_open)
                .content(jsonString)
                .build()
                .execute(callback);
    }

    public void registerTask(String jsonString, Callback callback) {
        OkHttpUtils.postString()
                .url(NetTaskList.register)
                .content(jsonString)
                .build()
                .execute(callback);
    }
    //获取验证码
    public void getVerifyTask(String jsonString, Callback callback) {
        OkHttpUtils
                .post()
//                .postString()
                .url(NetTaskList.getVerify)
//                .content(jsonString)
                .addParams("phone", "15588677273")
                .addParams("code_type", "1")
                .build()
                .execute(callback);
    }
    public static void getUserInfoTask() {
        OkHttpUtils.post().url(NetTaskList.get_userInfo)
                .addParams("token", AppInfo.TOKEN)
                .addParams("phone_type", AppInfo.PHONE_TYPE)
                .addParams("phone_system_version", AppInfo.getPhone_system_version())
                .addParams("phone_app_version", AppInfo.getPhone_app_version())
                .addParams("client_id", AppInfo.getClient_id())
                .addParams("user_id", AppInfo.loginInfo.getUserId())
                .build()
                .execute(new Callback<SimpleInfoData>() {
                    @Override
                    public SimpleInfoData parseNetworkResponse(Response response, int id) throws Exception {
                        String string = response.body().string();
                        Lo.e("getUserInfoTask", string);
                        SimpleInfoData infoBean = new Gson().fromJson(string, SimpleInfoData.class);
                        return infoBean;
                    }

                    @Override
                    public void onError(Call call, Exception e, int id) {

                    }

                    @Override
                    public void onResponse(SimpleInfoData response, int id) {
                        if(response.result == 0){
                            GUserInfo userInfo = new Gson().fromJson(response.data.getAsJsonObject(), GUserInfo.class);
                            Log.e("onResponse", userInfo.toString());
                            LoginInfo.getInstance().setgUserInfo(userInfo);
                        }
                    }
                });
    }

    public void getRoomId(Activity activity, int id, RequestNetCallback callback){

        ProgressDialogCallBack pcallback = new ProgressDialogCallBack(activity, callback);
        OkHttpUtils.post()
                .id(id)
                .tag(this.getClass().getName())
                .url(NetTaskList.room_id)
                .params(AppInfo.getHeadInfo())
                .build()
                .execute(pcallback);
    }
    public void createLive(Activity activity, int id, RequestNetCallback callback){

        ProgressDialogCallBack pcallback = new ProgressDialogCallBack(activity, callback);
        HashMap<String,String> params = new HashMap<String,String>();
//        params.put("title",AppInfo.getLiveTitle());
        params.put("title",CurLiveInfo.getTitle());
//        params.put("cover","");
//        params.put("city_id","392");
//        params.put("longitude","116");
//        params.put("latitude","40");
        params.put("room_id", LoginInfo.getInstance().getRoomId() +"");
        params.put("chat_room_id", LoginInfo.getInstance().getChatRoomId());
        params.putAll(AppInfo.getHeadInfo());

//        Log.e("live_id", params.toString());
        OkHttpUtils.post()
                .id(id)
                .tag(this.getClass().getName())
                .url(NetTaskList.create_live)
                .params(params)
                .build()
                .execute(pcallback);
    }
    public void endLive(Activity activity, int id, RequestNetCallback callback){

        ProgressDialogCallBack pcallback = new ProgressDialogCallBack(activity, callback);
        HashMap<String,String> params = new HashMap<String,String>();
        params.put("live_id", CurLiveInfo.getLiveId());
        params.putAll(AppInfo.getHeadInfo());
        OkHttpUtils.post()
                .id(id)
                .tag(this.getClass().getName())
                .url(NetTaskList.end_live)
                .params(params)
                .build()
                .execute(pcallback);
    }
    public void getLiveList(Activity activity, int id, RequestNetCallback callback){

        ProgressDialogCallBack pcallback = new ProgressDialogCallBack(activity, callback);
        HashMap<String,String> params = new HashMap<String,String>();
        params.put("page","1");
        params.put("page_count","20");
        params.putAll(AppInfo.getHeadInfo());
        OkHttpUtils.post()
                .id(id)
                .tag(this.getClass().getName())
                .url(NetTaskList.live_list)
                .params(params)
                .build()
                .execute(pcallback);
    }

}
